package top.chmin.project.cloud.common.entity.label.value.auto;

// field import auto
// #bind.field.dataApiType#

import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import top.chmin.project.cloud.common.entity.Page;
import top.chmin.project.cloud.common.tool.DatetimeTool;
import top.chmin.project.cloud.common.tool.LocalTool;

import java.time.LocalDateTime;

/**
 * chmin
 * 2023-12-27 11:22:22
 * cloud-builder
 */
@Slf4j
@Component
public class EntityLabelValuePlugin {

    public void checkSave(EntityLabelValueSave.Param param) {
        log.debug("checkSave-param: {}", JSONUtil.toJsonStr(param));
        if (param == null) {
            throw new RuntimeException("保存对象不能为空");
        }
    }

    public void beforeSave(EntityLabelValue entityLabelValue) {
        log.debug("beforeSave-entityLabelValue: {}", JSONUtil.toJsonStr(entityLabelValue));
        entityLabelValue.setCreateBy(LocalTool.getUserId());
        entityLabelValue.setUpdateBy(LocalTool.getUserId());
        entityLabelValue.setCreateTime(LocalDateTime.now());
        entityLabelValue.setUpdateTime(LocalDateTime.now());
    }

    public void afterSave(EntityLabelValueSave.Param param, EntityLabelValue entityLabelValue, int result) {
        log.debug("afterSave-param: {}", JSONUtil.toJsonStr(param));
        log.debug("afterSave-entityLabelValue: {}", JSONUtil.toJsonStr(entityLabelValue));
        log.debug("afterSave-result: {}", JSONUtil.toJsonStr(result));

    }

    public void checkUpdateById(EntityLabelValueUpdateById.Param param) {
        log.debug("checkUpdateById-param: {}", JSONUtil.toJsonStr(param));
        if (param == null) {
            throw new RuntimeException("更新对象不能为空");
        }
        if (param.getId() == null) {
            throw new RuntimeException("更新对象id不能为空");
        }
    }

    public void beforeUpdateById(EntityLabelValue entityLabelValue) {
        log.debug("beforeUpdateById-entityLabelValue: {}", JSONUtil.toJsonStr(entityLabelValue));
        entityLabelValue.setUpdateBy(LocalTool.getUserId());
        entityLabelValue.setUpdateTime(LocalDateTime.now());
    }

    public void afterUpdateById(EntityLabelValueUpdateById.Param param, EntityLabelValue entityLabelValue, int result) {
        log.debug("afterUpdateById-param: {}", JSONUtil.toJsonStr(param));
        log.debug("afterUpdateById-entityLabelValue: {}", JSONUtil.toJsonStr(entityLabelValue));
        log.debug("afterUpdateById-result: {}", JSONUtil.toJsonStr(result));

    }

    public void checkDeleteById(EntityLabelValueDeleteById.Param param) {
        log.debug("checkDeleteById-param: {}", JSONUtil.toJsonStr(param));
        if (param == null) {
            throw new RuntimeException("删除对象不能为空");
        }
        if (param.getId() == null) {
            throw new RuntimeException("删除对象id不能为空");
        }
    }

    public void afterDeleteById(EntityLabelValueDeleteById.Param param, int result) {
        log.debug("afterDeleteById-param: {}", JSONUtil.toJsonStr(param));
        log.debug("afterDeleteById-result: {}", JSONUtil.toJsonStr(result));

    }

    public void checkSelectById(EntityLabelValueSelectById.Param param) {
        log.debug("checkSelectById-param: {}", JSONUtil.toJsonStr(param));
        if (param == null) {
            throw new RuntimeException("查询对象不能为空");
        }
        if (param.getId() == null) {
            throw new RuntimeException("查询对象id不能为空");
        }
    }

    public void beforeSelectById(EntityLabelValueSelectById.Param param, EntityLabelValueFPC fpc) {
        log.debug("beforeSelectById-param: {}", JSONUtil.toJsonStr(param));

    }

    public void afterSelectById(EntityLabelValueSelectById.Param param, EntityLabelValueSelectById.Result result) {
        log.debug("afterSelectById-param: {}", JSONUtil.toJsonStr(param));
        log.debug("afterSelectById-result: {}", JSONUtil.toJsonStr(result));

    }

    public void checkSelectPage(EntityLabelValueSelectPage.Param param) {
        log.debug("checkSelectPage-param: {}", JSONUtil.toJsonStr(param));
        if (param == null) {
            throw new RuntimeException("分页对象不能为空");
        }
    }

    public void beforeSelectPage(EntityLabelValueSelectPage.Param param, EntityLabelValueFPC fpc) {
        log.debug("beforeSelectPage-param: {}", JSONUtil.toJsonStr(param));
// field beforeSelectPage auto
// #bind.field.createBy#
        fpc.createBy().eq(param.getCreateBy());
// $bind.field.createBy$

// #bind.field.updateBy#
        fpc.updateBy().eq(param.getUpdateBy());
// $bind.field.updateBy$

// #bind.field.createTime#
        fpc.createTime().ge(param.getCreateTime() == null || param.getCreateTime().length == 0 ? null : param.getCreateTime()[0]);
        fpc.createTime().lt(param.getCreateTime() == null || param.getCreateTime().length < 2 ? null : DatetimeTool.nextDay(param.getCreateTime()[1]));
// $bind.field.createTime$

// #bind.field.updateTime#
        fpc.updateTime().ge(param.getUpdateTime() == null || param.getUpdateTime().length == 0 ? null : param.getUpdateTime()[0]);
        fpc.updateTime().lt(param.getUpdateTime() == null || param.getUpdateTime().length < 2 ? null : DatetimeTool.nextDay(param.getUpdateTime()[1]));
// $bind.field.updateTime$

// #bind.field.tableCode#
        fpc.tableCode().eq(param.getTableCode());
// $bind.field.tableCode$

// #bind.field.labelFieldCode#
        fpc.labelFieldCode().eq(param.getLabelFieldCode());
// $bind.field.labelFieldCode$

// #bind.field.valueFieldCode#
        fpc.valueFieldCode().eq(param.getValueFieldCode());
// $bind.field.valueFieldCode$

// #bind.field.dataApiType#
        fpc.dataApiType().eq(param.getDataApiType());
// $bind.field.dataApiType$

    }

    public void afterSelectPage(EntityLabelValueSelectPage.Param param, Page<EntityLabelValueSelectPage.Result> result) {
        log.debug("afterSelectPage-param: {}", JSONUtil.toJsonStr(param));
        log.debug("afterSelectPage-result: {}", JSONUtil.toJsonStr(result));

    }

// entity select auto

// entity search auto
}
